<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>百度换肤</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background: url(./images/1.jpg) no-repeat;
        }

        .box {
            margin: 100px auto;
            width: 410px;
            height: 65px;
            background-color: white;
        }

        .box img {
            margin: 1px;
            float: left;
            width: 100px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="box">
        <img src="./images/1.jpg" alt="" class="b1">
        <img src="./images/2.jpg" alt="" class="b2">
        <img src="./images/3.jpg" alt="" class="b3">
        <img src="./images/4.jpg" alt="" class="b4">
    </div>
    <script>
        let imgs = document.querySelector('.box').querySelectorAll('img');
        let body = document.body;

        for (let i = 0; i < imgs.length; i++) {
            imgs[i].onclick = function () {
                body.style.background = 'url(./images/' + (i + 1) + '.jpg) no-repeat';
            }
        }
    </script>
</body>

</html>